﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

namespace Weazel.Badger.Vhdl.Types
{
  public abstract class ArrayType : Type
  {
    public static readonly int UNDEFINED_WIDTH = -1;

    public bool UndefinedWidth
    {
      get
      {
        return Width == UNDEFINED_WIDTH;
      }
    }

		/// <summary>
		/// The type of the elements of this array
		/// </summary>
    private Type elementType;
    public Type ElementType
    {
      get
      {
        return elementType;
      }

      set
      {
        elementType = value;
      }
    }

    public ArrayType(TypeId type, int width, Type elementType) : base(type, width)
    {
			if (width < 1)
			{
				string message =
					string.Format("Array type width must be greater than 0 (actual: {0})", width);

				throw new NotSupportedException(message);
			}

      this.elementType = elementType;
    }

    public override int GetHashCode()
    {
      return base.GetHashCode() & (Width << 32);
    }

		/// <summary>
		/// Compare this array type with another type
		/// </summary>
		/// <param name="t"></param>
		/// <returns>true if same</returns>
    public override bool Compare(Type t)
    {
      if (t is ArrayType)
      {
        return base.Compare(t) && ((ArrayType)t).Width == Width;
      }
      else
        return false;
    }
  }
}
